<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}

$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
    include "../../value/value_en.php";
} else if ($lang == "VN") {
    include "../../value/value_vn.php";
} else {
    include "../../value/value_kr.php";
}
include '../../content-accountant/invoicetax.php';
include '../../operations/connection.php';
$tongtieninput = 0;
$tongcong = 0;
$_SESSION['input_invoice'] = array();
$ob = new invoicetax();
$ob->newinvoicetax();

$status = $_REQUEST['status'];
if ($status == 0) {
    $l_ngaygiaodich = $l_ngaygiaodich0;
    $l_ngayphathanh = $l_ngayphathanh0;
    $l_thoigiangiaodich = $l_thoigiangiaodich0;
}
if ($status == 1) {
    $l_ngaygiaodich = $l_ngaygiaodich1;
    $l_ngayphathanh = $l_ngayphathanh1;
    $l_thoigiangiaodich = $l_thoigiangiaodich1;
}
$ob->ormonth = $_REQUEST['thang'];
$ob->oryear = $_REQUEST['nam'];
if ($_REQUEST['thang'] == date('m') && $_REQUEST['nam'] == date('Y')) {
    $ob->orday = date('d');
} else {
    $ob->orday = 1;
}
$_SESSION['input_invoice'][] = $ob;
?>
<style type="text/css">
    .content_menu_expand{
        position:absolute; 
        right:-5px;
        top:20px;
        z-index:999;
        background-color: #ffffff;
        -moz-border-radius: 7px;
        -webkit-border-radius: 7px;
        color: #000000;
        width:300px;
        max-height:180px;
        overflow:auto;
    }
</style>
<div>
    <form action="" method="post"
          name="formexcel" enctype="multipart/form-data">
        <input name="fileexcel" type="file" value="ad" onchange="document.formexcel.submit()" style="width:200px;height:24px;" />
    </form>
</div>
<div>
    <input onclick="add(<?=$status ?>);" type="button" value="+" id="btadd" name="btadd" class="btnupbg btnupload" style="width:50px;font-size:20px;background: #4f81bd;"/> 
</div>
<div style="position:relative" id="showinput">
    <table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable">
        <tr >
            <th style="width:10px"></th>
            <?php if($status==1){?><th style="width:10px"></th><?php }?>
            <th style="width:10px"><?= $l_no ?></th>
            <th style="width:30px"><?= $l_month ?></th>
            <th style="width:30px"><?= $l_days ?></th>
            <th style="width:200px"><?= $l_customer ?></th>
            <th style="width:40%"><?= $l_product_item ?></th>
            <th style="width:50px;display: none"><?= $l_quantity ?></th>
            <th style="width:90px"><?= $l_Supply_price ?></th>
            <th style="width:90px"><?= $l_vat ?></th>
            <th style="width:90px"><?= $l_amount ?></th>
            <th style="width:90px"><?= $l_thoigiangiaodich ?></th> 
            <th style="width:90px;<?php if($status==0) echo 'display: none'?>"><?= $l_payment ?></th> 
            <th style="min-width:120px"><?= $l_memo ?></th>
        </tr>
<?php
if (isset($_SESSION['input_invoice']) && count($_SESSION['input_invoice']) > 0) {
    for ($i = 0; $i < count($_SESSION['input_invoice']); $i++) {
        $inobject = unserialize(serialize($_SESSION['input_invoice'][$i]));
        ?>
                <tr >
                    <td><img onclick="deleteclick(<?= $i ?>,<?= $status ?>)" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete; ?>" /></td>
                    <?php if($status==1){?><td><input type="checkbox" id="<? echo "red" . $i ?>" name="red[]"  <?php if($inobject->red==1) echo 'checked="checked"';?> onchange="chRed(this,<?= $i ?>,'red');"></td><?php }?> 
                    <td><p style="width: 20px"><?= ($i + 1) ?></p></td>
                    <td><p style="width: 20px"><?= $inobject->ormonth ?></p></td>
                    <td>
                        <a href="#?w=200" rel="popup_name3" onclick="popuploadbel_invoice_tax_day(this,<?= $i ?>);" class="poplight"><input type="text" readonly="readonly" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'1')" id="<? echo "txtday" . $i ?>" name="vday[]" style="height: 24px; width:30px; border: 1px solid #c4c0c9;line-height: 24px;font-size:12px;text-align:center;"	value="<?= $inobject->orday ?>" autocomplete="off"  /></a>
                    </td>
                    <td style="padding:3px">
                        <div style="position:relative; ">
                            <div style="float:left;">
                                <input  type="text" size="30" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'0')" onchange="chText(this.value,<?= $i ?>,'txtcusname');" onkeyup="chText(this.value,<?= $i ?>,'txtcusname');" id="<? echo "txtcusname" . $i ?>" name="vcusname[]" value="<?= $inobject->cusname ?>"  style="height: 24px; width: 220px; border: 1px solid #c4c0c9;font-size: 12px;" autocomplete="off"; />
                                        <div class="suggestionsBox" id="suggestions" style="display:none;">
                                    <img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
                                    <div class="suggestionList" id="autoSuggestionsList">
                                        &nbsp;
                                    </div>
                                </div> 						
                            </div>
                            <div style=" float:left; position:relative; margin-top: 5px; margin-left: -21px">
                                <img alt="" src="images/arrow-down.png" id="<? echo "menu_expand" . $i; ?>" >
                                <div id="<? echo "content_menu_expand" . $i; ?>" class="passul content_menu_expand" style="display:none;text-align: left;width: 220px;">
                                    <ul>
        <?php
        $sql = "select ac_customer.CustomerName from ac_customer where ac_customer.Activest=1";
        $result = mysql_query($sql);
        if ($result) {
            $j = 0;
            while ($row = mysql_fetch_array($result)) {
                ?>
                                                <li onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'" onclick="clickCustomer('<?= $row['CustomerName'] ?>','<?= $i ?>','txtcusname')" 
                                                <?php
                                                if ($j % 2 != 0) {
                                                    ?>
                                                        class="bgkhac"
                                                    <?php
                                                }
                                                ?>
                                                    > <?php echo $row['CustomerName']; ?></li>
                                                    <?php
                                                    $j++;
                                                }
                                            }
                                            ?>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td >
                        <input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'0')" onchange="chText(this.value,<?= $i ?>,'txtitem');" onkeyup="chText(this.value,<?= $i ?>,'txtitem');" id="<? echo "txtitem" . $i ?>" name="vitem[]" style="height: 24px;width: 98%; border: 1px solid #c4c0c9;line-height: 24px;font-size:12px;"	value="<?= $inobject->order_content ?>" autocomplete="off"  />
                    </td>
                    <td style="display: none;">
                        <input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'1')" onchange="chQuan(this.value,<?= $i ?>,'txtquantity');" onkeyup="chQuan(this.value,<?= $i ?>,'txtquantity');" id="<? echo "txtquantity" . $i ?>" name="vquantity[]" style="height: 24px;width: 30px; border: 1px solid #c4c0c9;line-height: 24px;text-align:center;font-size:12px;"	value="<?= number_format($inobject->order_quantity) ?>" autocomplete="off"  />
                    </td>
                    <td id="<? echo "otxtrice" . $i ?>" >
                        <input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'1')" onchange="chRice(this.value,<?= $i ?>,'txtrice');" onkeyup="chRice(this.value,<?= $i ?>,'txtrice');" id="<? echo "txtrice" . $i ?>" name="vrice[]" style="height: 24px; width: 90px; border: 1px solid #c4c0c9;line-height: 24px;text-align:right;padding-right:3px;font-size:12px;"	value="<?= number_format($inobject->order_suplly_rice) ?>" autocomplete="off"  />
                    </td>
                    <td id="<? echo "vintax" . $i ?>" >
                        <input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'1')" onchange="chTax(this.value,<?= $i ?>,'vintax');" onkeyup="chTax(this.value,<?= $i ?>,'vintax');" id="<? echo "vointax" . $i ?>" name="ovointax[]" style="height: 24px; width: 90px; border: 1px solid #c4c0c9;line-height: 24px;text-align:right;padding-right:3px;font-size:12px;"	value="<?= number_format($inobject->order_tax) ?>" autocomplete="off"  />
                    </td>
                    <td style="text-align:right;padding-right:3px;min-width: 90px" id="<? echo "vintotal" . $i ?>"><p style="min-width: 90px"><?= number_format($inobject->order_total) ?></p></td>
                    <td style="padding:3px;">
                        <input type="text"  onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'0')" onfocus="chText(this.value,<?= $i ?>,'txttimetran');" onkeyup="chText(this.value,<?= $i ?>,'txttimetran');" id="<? echo "txttimetran" . $i ?>" name="vtimetran[]" style="height: 24px; width: 90px; border: 1px solid #c4c0c9;line-height: 24px;text-align:center;font-size:12px;"	
                               value="<?php
                                    if ($inobject->nstatus == 1)
                                        echo "-";
                                    else
                                        echo $inobject->order_time_transaction;
                                    ?>"

                               autocomplete="off"  />
                               <!--  <small><a style="font-size: 12px" href="javascript:showCal('<?php echo "Calendar" . $i; ?>')"><img src="images/calendars.png" title="<?php echo $l_choosedate; ?>" /></a></small>-->
                    </td> 
                    <td style="padding:3px;<?php if($status==0) echo 'display: none'?>">
                                    <input type="text"  onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'0')" onfocus="chText(this.value,<?= $i ?>,'txttimepayment');" onkeyup="chText(this.value,<?= $i ?>,'txttimepayment');" id="<? echo "txttimepayment" . $i ?>" name="vtimepayment[]" style="height: 24px; width: 90px; border: 1px solid #c4c0c9;line-height: 24px;text-align:center;font-size:12px;"	value="<?= $inobject->order_time_payment ?>" autocomplete="off"  />
                    </td>
                    <td style="padding:3px">
                        <input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($_SESSION['input_invoice']); ?>,'0')" onfocus="chText(this.value,<?= $i ?>,'txtmemo');" onkeyup="chText(this.value,<?= $i ?>,'txtmemo');" id="<? echo "txtmemo" . $i ?>" name="vmemo[]" style="height: 24px; width: 120px; border: 1px solid #c4c0c9;line-height: 24px;text-align:center;font-size:12px;"	value="<?= $inobject->order_memo ?>" autocomplete="off"  />
                    </td>
                </tr>
        <?php
        $tongtieninput +=$inobject->order_total;
        $tongcong +=$inobject->order_total;
    }
}else {
    ?>
            <tr><td colspan="11" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty; ?></td></tr>
        <?php } ?>
        <tr class="coltr2" style="height:30px;font-weight:bold;">
            <td colspan="5"></td>
            <?php if($status==1){?><td></td><?php }?>
            <td></td>
            <td style="display: none;"></td>
            <td></td>
            <td></td>
            <td style="text-align:right;padding-right:3px;" id="vinsum"><?php echo number_format($tongtieninput); ?></td>
            <td>(yyyy-mm-dd)</td>
            <td style="<?php if($status==0) echo 'display: none'?>">(yyyy-mm-dd)</td>
            <td></td>
        </tr>            
    </table>       
    <div id="temptb"><input type="hidden" value="<?= count($_SESSION['input_invoice']) ?>" id="soluongphantu" /></div>
</div>
<div style="width:100%;text-align:center;padding-top:20px;" ><input onclick="save(<?= $status ?>);" type="button" style="background: #4f81bd;" value="<?= $l_save ?>" class="btnupbg btnupload" /></div>      
<?php mysql_close($connection); ?>